package com.bootdo.system.service.impl;

import com.bootdo.system.dao.FrontlogDao;
import com.bootdo.system.domain.DayLogVO;
import com.bootdo.system.domain.FrontlogDO;
import com.bootdo.system.service.FrontlogService;
import com.huobi.model.trade.Order;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class FrontlogServiceImpl implements FrontlogService {
	@Autowired
	private FrontlogDao frontlogDao;

    @Override
    public void savelog(String logbeizhu, Order order, long userid, String jiaoyitype) {
		FrontlogDO frontlogDO = new FrontlogDO();
		frontlogDO.setBeizhu(logbeizhu);
		frontlogDO.setBizhongname(order.getSymbol());
		frontlogDO.setNum(order.getFilledAmount());
		frontlogDO.setChengjiaojia(order.getFilledCashAmount());
		frontlogDO.setUserid(userid);
		frontlogDO.setCreatetime(new Date());
		frontlogDO.setContent("成功修改持仓数据");
		frontlogDO.setJiaoyitype(jiaoyitype);
		save(frontlogDO);
    }

    @Override
	public FrontlogDO get(Long id){
		return frontlogDao.get(id);
	}
	
	@Override
	public List<FrontlogDO> list(Map<String, Object> map){
		return frontlogDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return frontlogDao.count(map);
	}
	
	@Override
	public int save(FrontlogDO frontlog){
		return frontlogDao.save(frontlog);
	}
	
	@Override
	public int update(FrontlogDO frontlog){
		return frontlogDao.update(frontlog);
	}
	
	@Override
	public int remove(Long id){
		return frontlogDao.remove(id);
	}
	
	@Override
	public int batchRemove(Long[] ids){
		return frontlogDao.batchRemove(ids);
	}

    @Override
    public List<String> getUserDates(Long userId) {

		return frontlogDao.getUserDates(userId);
    }

	@Override
	public List<DayLogVO> getdaylog(Long userId, List<String> dates) {

		List<DayLogVO> dayLogVOS= new ArrayList<>();

		for (String date:dates) {
			DayLogVO dayLogVO = new DayLogVO();
			dayLogVO.setDate(date);
			try {
				if(StringUtils.isNotEmpty(date)){
					Date showdate = new SimpleDateFormat("yyyyMMdd").parse(date);
					dayLogVO.setShowdate(showdate);
				}

			} catch (ParseException e) {
				e.printStackTrace();
			}
			List<FrontlogDO> frontlogDOS = frontlogDao.getDayList(userId,date);
			dayLogVO.setLogs(frontlogDOS);

			dayLogVOS.add(dayLogVO);
		}

		return dayLogVOS;
	}

	@Override
	public List<FrontlogDO> getBeizhu(int adminid, Long transactId) {
		return  frontlogDao.getBeizhu(adminid, transactId);
	}

    @Override
    public void saveSellLog(Long userid, int jiaoyitype, String bizhongname, String content, BigDecimal chicangshuliang, BigDecimal chicangjunjia, String clientOrderId) {
		FrontlogDO frontlogDO = new FrontlogDO();
		frontlogDO.setUserid(userid);
		frontlogDO.setJiaoyitype(jiaoyitype+"");
		frontlogDO.setBizhongname(bizhongname);
		frontlogDO.setContent(content);
		frontlogDO.setNum(chicangshuliang);
		frontlogDO.setChengjiaojia(chicangjunjia);
		frontlogDO.setCreatetime(new Date());
		frontlogDO.setBeizhu(clientOrderId);

		frontlogDao.save(frontlogDO);
	}

    @Override
    public void deleyeByBeizhu(String beizhu) {
        frontlogDao.deleteByBeizhu(beizhu);
    }

	@Override
	public FrontlogDO getByBeizhu(String s) {
		return frontlogDao.getByBeizhu(s);
	}


}
